/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JF_VerUsuarios.java
 *
 * Created on 09-mar-2010, 21:16:33
 */

package cliente.presentacion.administrador.gestionusuario;


import cliente.negocio.Controlador_Gestion_Usuarios;
import java.awt.Toolkit;
import server.dominio.Usuario;

/**
 *
 * @author tpaxle
 */
public class JF_VerUsuarios extends javax.swing.JFrame implements iJF_VerUsuario{

  private Controlador_Gestion_Usuarios controlador;
  private Usuario usuariomostrado= null;
  private int seleccionado= -1;
    public JF_VerUsuarios(Controlador_Gestion_Usuarios controlador, int selec) {
        initComponents();
        this.controlador= controlador;
        seleccionado= selec;
        this.setLocation((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/4,(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()/6);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        jLabel15 = new javax.swing.JLabel();
        jTextField_password = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        jTextField_login = new javax.swing.JTextField();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        jLabel17 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jTextField_mail = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jTextField_nombre = new javax.swing.JTextField();
        jTextField_apellidos = new javax.swing.JTextField();
        jTextField_NIF = new javax.swing.JTextField();
        jTextField_domicilio = new javax.swing.JTextField();
        jTextField_tel_fijo = new javax.swing.JTextField();
        jTextField_telefono_movil = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1268112244_preferences-desktop-user.png"))); // NOI18N

        jLayeredPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Datos de usuario"));
        jLayeredPane2.setEnabled(false);

        jLabel15.setText("Pass:");
        jLabel15.setBounds(20, 70, 40, 16);
        jLayeredPane2.add(jLabel15, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_password.setEnabled(false);
        jTextField_password.setBounds(70, 70, 150, 20);
        jLayeredPane2.add(jTextField_password, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel16.setText("Rol:");
        jLabel16.setBounds(20, 100, 40, 20);
        jLayeredPane2.add(jLabel16, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administrador", "Citador", "Medico", " ", " " }));
        jComboBox4.setEnabled(false);
        jComboBox4.setBounds(70, 100, 170, 22);
        jLayeredPane2.add(jComboBox4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel19.setText("Login:");
        jLabel19.setBounds(20, 40, 40, 16);
        jLayeredPane2.add(jLabel19, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_login.setEnabled(false);
        jTextField_login.setBounds(70, 40, 150, 20);
        jLayeredPane2.add(jTextField_login, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLayeredPane3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Datos personales"));
        jLayeredPane3.setEnabled(false);

        jLabel17.setText("Fecha de nacimiento:");
        jLabel17.setBounds(10, 200, 130, 16);
        jLayeredPane3.add(jLabel17, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField2.setEnabled(false);
        jTextField2.setBounds(260, 200, 40, 20);
        jLayeredPane3.add(jTextField2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel18.setText("Nombre:");
        jLabel18.setBounds(10, 40, 70, 16);
        jLayeredPane3.add(jLabel18, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel20.setText("Apellidos:");
        jLabel20.setBounds(10, 70, 70, 16);
        jLayeredPane3.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel21.setText("NIF:");
        jLabel21.setBounds(270, 40, 30, 16);
        jLayeredPane3.add(jLabel21, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel22.setText("Domicilio:");
        jLabel22.setBounds(10, 100, 70, 16);
        jLayeredPane3.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel23.setText("Telf. Fijo:");
        jLabel23.setBounds(10, 130, 70, 16);
        jLayeredPane3.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel24.setText("Telf. Movil:");
        jLabel24.setBounds(230, 130, 70, 16);
        jLayeredPane3.add(jLabel24, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel25.setText("/");
        jLabel25.setBounds(250, 200, 10, 16);
        jLayeredPane3.add(jLabel25, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_mail.setEnabled(false);
        jTextField_mail.setBounds(100, 160, 330, 20);
        jLayeredPane3.add(jTextField_mail, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField5.setEnabled(false);
        jTextField5.setBounds(160, 200, 40, 20);
        jLayeredPane3.add(jTextField5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField6.setEnabled(false);
        jTextField6.setBounds(210, 200, 40, 20);
        jLayeredPane3.add(jTextField6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel26.setText("Email:");
        jLabel26.setBounds(10, 160, 70, 16);
        jLayeredPane3.add(jLabel26, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel27.setText("/");
        jLabel27.setBounds(200, 200, 10, 16);
        jLayeredPane3.add(jLabel27, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_nombre.setEnabled(false);
        jTextField_nombre.setBounds(100, 40, 140, 20);
        jLayeredPane3.add(jTextField_nombre, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_apellidos.setEnabled(false);
        jTextField_apellidos.setBounds(100, 70, 330, 20);
        jLayeredPane3.add(jTextField_apellidos, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_NIF.setEnabled(false);
        jTextField_NIF.setBounds(310, 40, 120, 20);
        jLayeredPane3.add(jTextField_NIF, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_domicilio.setEnabled(false);
        jTextField_domicilio.setBounds(100, 100, 330, 20);
        jLayeredPane3.add(jTextField_domicilio, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_tel_fijo.setEnabled(false);
        jTextField_tel_fijo.setBounds(100, 130, 110, 20);
        jLayeredPane3.add(jTextField_tel_fijo, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jTextField_telefono_movil.setEnabled(false);
        jTextField_telefono_movil.setBounds(310, 130, 120, 20);
        jLayeredPane3.add(jTextField_telefono_movil, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton4.setText("OK");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton1.setText("Modificar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLayeredPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLayeredPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLayeredPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 47, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
}//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        controlador.modificarusuario(seleccionado);
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField_NIF;
    private javax.swing.JTextField jTextField_apellidos;
    private javax.swing.JTextField jTextField_domicilio;
    private javax.swing.JTextField jTextField_login;
    private javax.swing.JTextField jTextField_mail;
    private javax.swing.JTextField jTextField_nombre;
    private javax.swing.JTextField jTextField_password;
    private javax.swing.JTextField jTextField_tel_fijo;
    private javax.swing.JTextField jTextField_telefono_movil;
    // End of variables declaration//GEN-END:variables


     public void mostrar(Usuario usuario, int index) {
        seleccionado= index;
        if (usuario != null) {
            usuariomostrado= usuario;
            jTextField_login.setText(usuario.getLogin());
            jTextField_password.setText(usuario.getPass());
            jTextField_nombre.setText(usuario.getNombre());
            jTextField_NIF.setText(usuario.getNif());
            jTextField_apellidos.setText(usuario.getApellidos());
            jTextField_domicilio.setText(usuario.getDomicilio());
            jTextField_mail.setText(usuario.getEmail());
            jTextField_tel_fijo.setText("" + usuario.getTeleFijo());
            jTextField_telefono_movil.setText("" + usuario.getTeleMovil());
            System.out.println(usuario.getFecha_nacimiento());
            jTextField2.setText(usuario.getFecha_nacimiento().substring(0, 4));
            jTextField6.setText(usuario.getFecha_nacimiento().substring(5, 7));
            jTextField5.setText(usuario.getFecha_nacimiento().substring(8, 10));
            jComboBox4.setSelectedIndex((int)usuario.getRol().getIdRol_pk()-1);
            this.setVisible(true);

        } else {
            this.setVisible(false);
           // controlador.log("Error, el usuario n0 ha sido pasado");
        }

    }


}
